/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UI;

import Service.Impl.AccountManagerImpl;
import Service.Impl.BranchesManagerImpl;
import Service.Impl.LoanDetailImp;
import Service.Impl.LoanTypeImp;
import java.awt.Toolkit;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.RowFilter;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Hoang Minh
 */
public class LoanDetailsFrm extends javax.swing.JFrame {

    LoanDetailImp LD;
    ResultSet rs;
    DefaultTableModel model;
    AccountManagerImpl acc;
    BranchesManagerImpl bra;
    Vector VecAcc;
    Vector VecBra;
    ResultSet rsLoanType;

    /**
     * Creates new form LoanDetailsFrm
     */
    public LoanDetailsFrm() {
        initComponents();
        int h = Toolkit.getDefaultToolkit().getScreenSize().height;
        int w = Toolkit.getDefaultToolkit().getScreenSize().width;
        setSize(w, h);
        loadData();
    }

    public LoanDetailsFrm(String AccNo) {
        initComponents();
        int h = Toolkit.getDefaultToolkit().getScreenSize().height;
        int w = Toolkit.getDefaultToolkit().getScreenSize().width;
        setSize(w, h);
        PnlInfor.setBounds(0, 0, w / 4, h);
        loadData(AccNo);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tblLoanDetails = new javax.swing.JTable();
        container = new javax.swing.JPanel();
        PnlInfor = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        lblStatus = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        cboLoanType = new javax.swing.JComboBox();
        cboBranch = new javax.swing.JComboBox();
        cboAccount = new javax.swing.JComboBox();
        lblBeginTime = new javax.swing.JLabel();
        lblEndTime = new javax.swing.JLabel();
        lblLoanMoney = new javax.swing.JLabel();
        lblCurrentMoney = new javax.swing.JLabel();
        btnLoanTypeManager = new javax.swing.JButton();
        Reset = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        btnUpdate = new javax.swing.JButton();
        btnAdd = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Loan Details");
        setName("frmLoanDetails");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                reload(evt);
            }
        });

        jScrollPane1.setViewportBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(153, 153, 0)));

        tblLoanDetails.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                ""
            }
        ));
        tblLoanDetails.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        tblLoanDetails.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                chooseRow(evt);
            }
        });
        jScrollPane1.setViewportView(tblLoanDetails);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        container.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(240, 240, 240)));
        container.setPreferredSize(new java.awt.Dimension(340, 468));

        PnlInfor.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Information"));
        PnlInfor.setPreferredSize(new java.awt.Dimension(200, 200));

        jLabel1.setText("Current Money:");
        jLabel1.setPreferredSize(new java.awt.Dimension(20, 14));

        jLabel2.setText("Loan Money:");

        jLabel3.setText("Account No:");
        jLabel3.setPreferredSize(new java.awt.Dimension(20, 14));

        jLabel4.setText("Begin Time:");
        jLabel4.setPreferredSize(new java.awt.Dimension(20, 14));

        jLabel5.setText("Loan Type:");
        jLabel5.setPreferredSize(new java.awt.Dimension(20, 14));

        jLabel6.setText("Branch:");
        jLabel6.setPreferredSize(new java.awt.Dimension(20, 14));

        jLabel7.setText("End Time:");
        jLabel7.setPreferredSize(new java.awt.Dimension(20, 14));

        lblStatus.setText("not set");
        lblStatus.setPreferredSize(new java.awt.Dimension(20, 14));

        jLabel9.setText("Status");
        jLabel9.setPreferredSize(new java.awt.Dimension(20, 14));

        cboLoanType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "        -- Loan Type --" }));

        cboBranch.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "       -- Branch name --" }));

        cboAccount.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "        --Account No--" }));

        lblBeginTime.setText("not set");
        lblBeginTime.setPreferredSize(new java.awt.Dimension(20, 14));

        lblEndTime.setText("not set");
        lblEndTime.setPreferredSize(new java.awt.Dimension(20, 14));

        lblLoanMoney.setText("not set");
        lblLoanMoney.setPreferredSize(new java.awt.Dimension(20, 14));

        lblCurrentMoney.setText("not set");
        lblCurrentMoney.setPreferredSize(new java.awt.Dimension(20, 14));

        btnLoanTypeManager.setText("Loan Type Manager");
        btnLoanTypeManager.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLoanTypeManagerActionPerformed(evt);
            }
        });

        Reset.setText("Reset");
        Reset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ResetActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout PnlInforLayout = new javax.swing.GroupLayout(PnlInfor);
        PnlInfor.setLayout(PnlInforLayout);
        PnlInforLayout.setHorizontalGroup(
            PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PnlInforLayout.createSequentialGroup()
                .addGroup(PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PnlInforLayout.createSequentialGroup()
                        .addGroup(PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE)
                                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cboAccount, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cboBranch, 0, 158, Short.MAX_VALUE)
                            .addComponent(lblBeginTime, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblEndTime, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cboLoanType, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblLoanMoney, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblCurrentMoney, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(PnlInforLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnLoanTypeManager, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(Reset, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        PnlInforLayout.setVerticalGroup(
            PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PnlInforLayout.createSequentialGroup()
                .addGroup(PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(1, 1, 1)
                .addGroup(PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblLoanMoney, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCurrentMoney, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboLoanType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblBeginTime, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblEndTime, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboBranch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(PnlInforLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnLoanTypeManager, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Reset, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        btnUpdate.setText("Change Loan data");
        btnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdateActionPerformed(evt);
            }
        });

        btnAdd.setText("Add new Loan");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        btnDelete.setText("Delete");
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(btnUpdate)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAdd)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(21, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout containerLayout = new javax.swing.GroupLayout(container);
        container.setLayout(containerLayout);
        containerLayout.setHorizontalGroup(
            containerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(containerLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(containerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(PnlInfor, javax.swing.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE)
                    .addGroup(containerLayout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 1, Short.MAX_VALUE)))
                .addContainerGap())
        );
        containerLayout.setVerticalGroup(
            containerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(containerLayout.createSequentialGroup()
                .addComponent(PnlInfor, javax.swing.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(42, 42, 42))
        );

        getContentPane().add(container, java.awt.BorderLayout.WEST);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void chooseRow(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chooseRow
        // TODO add your handling code here:
        int row = tblLoanDetails.getSelectedRow();
        lblLoanMoney.setText(model.getValueAt(row, 4).toString());
        lblCurrentMoney.setText(model.getValueAt(row, 5).toString());
        lblBeginTime.setText(model.getValueAt(row, 6).toString());
        lblEndTime.setText(model.getValueAt(row, 7).toString());
        cboAccount.setSelectedItem(model.getValueAt(row, 0));
        cboBranch.setSelectedItem(model.getValueAt(row, 8));
        cboLoanType.setSelectedItem(model.getValueAt(row, 2));
    }//GEN-LAST:event_chooseRow

    private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
        int row = tblLoanDetails.getSelectedRow();
        if (tblLoanDetails.getSelectedRow() >= 0) {
            try {
                rs.absolute(row + 1);
                int ID = rs.getInt("LoanID");
                ManageLoan ML = new ManageLoan(ID);
                ML.setVisible(true);
                dispose();
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, "error with database");
            }
        } else {
            JOptionPane.showMessageDialog(null, "please choose one row.");
        }
    }//GEN-LAST:event_btnUpdateActionPerformed

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
        if (tblLoanDetails.getSelectedRow() >= 0) {
            try {
                int index = tblLoanDetails.getSelectedRow();
                int confirm = JOptionPane.showConfirmDialog(null, "delete this Loan?", "delete", JOptionPane.YES_NO_OPTION);
                if (confirm == JOptionPane.YES_OPTION) {
                    rs.absolute(index + 1);
                    if (LD.DelLoanDetail(rs.getInt("LoanID"))) {
                        JOptionPane.showMessageDialog(null, "Delete done");
                        model.removeRow(index);
                    }
                }
                new LoanDetailsFrm().setVisible(true);
                dispose();
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, ex);
            }
        } else {
            JOptionPane.showMessageDialog(null, "please choose one row.");
        }

    }//GEN-LAST:event_btnDeleteActionPerformed

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        ManageLoan ML = new ManageLoan();
        ML.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_btnAddActionPerformed

    private void reload(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_reload
    }//GEN-LAST:event_reload

    private void ResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ResetActionPerformed
        new LoanDetailsFrm().setVisible(true);
        dispose();
    }//GEN-LAST:event_ResetActionPerformed

    private void btnLoanTypeManagerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoanTypeManagerActionPerformed
        LoanTypeManagerFrm loanTypeManager = new LoanTypeManagerFrm();
    }//GEN-LAST:event_btnLoanTypeManagerActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(LoanDetailsFrm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(LoanDetailsFrm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(LoanDetailsFrm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(LoanDetailsFrm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new LoanDetailsFrm("C1011L0011          ").setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel PnlInfor;
    private javax.swing.JButton Reset;
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnLoanTypeManager;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JComboBox cboAccount;
    private javax.swing.JComboBox cboBranch;
    private javax.swing.JComboBox cboLoanType;
    private javax.swing.JPanel container;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblBeginTime;
    private javax.swing.JLabel lblCurrentMoney;
    private javax.swing.JLabel lblEndTime;
    private javax.swing.JLabel lblLoanMoney;
    private javax.swing.JLabel lblStatus;
    private javax.swing.JTable tblLoanDetails;
    // End of variables declaration//GEN-END:variables

    private void loadData() {
        try {
            LD = new LoanDetailImp();
            rs = LD.getAllLoanDetail();
            model = new DefaultTableModel();
            ResultSetMetaData RSmetaData = rs.getMetaData();
            int colNum = RSmetaData.getColumnCount();
            for (int i = 1; i < colNum + 1; i++) {
                String comName = RSmetaData.getColumnName(i);
                model.addColumn(comName);
            }
            Object[] row = new Object[colNum];
            while (rs.next()) {
                for (int j = 1; j < colNum + 1; j++) {
                    row[j - 1] = rs.getObject(j);
                }
                model.addRow(row);
            }

            LD = new LoanDetailImp();
            LoanTypeImp LT = new LoanTypeImp();
            rsLoanType = LT.getAllLoanType();
            while (rsLoanType.next()) {
                cboLoanType.addItem(rsLoanType.getString("TypeName"));
            }
            acc = new AccountManagerImpl();
            VecAcc = acc.getAll();
            int numAcc = VecAcc.size();
            for (int i = 0; i < numAcc; i++) {
                Vector v = (Vector) VecAcc.get(i);
                cboAccount.addItem(v.get(0));
            }

            bra = new BranchesManagerImpl();
            VecBra = bra.GetListFromTable("Select * From [Branches]");
            int numBra = VecBra.size();
            for (int i = 0; i < numBra; i++) {
                Vector v = (Vector) VecBra.get(i);
                cboBranch.addItem(v.get(1));
            }
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
        tblLoanDetails.setModel(model);
        tblLoanDetails.removeColumn(tblLoanDetails.getColumn("AccountNo"));
        tblLoanDetails.removeColumn(tblLoanDetails.getColumn("Expr1"));
        tblLoanDetails.removeColumn(tblLoanDetails.getColumn("LoanID"));
        tblLoanDetails.getColumn("Name").setHeaderValue("Customer Name");
        tblLoanDetails.getColumn("TypeName").setHeaderValue("Loan type");
        tblLoanDetails.getColumn("LoanMoney").setHeaderValue("Original Loan");
        tblLoanDetails.getColumn("CurentMoney").setHeaderValue("Remaining Amount");
        tblLoanDetails.getColumn("BeginTime").setHeaderValue("Start Time");
        tblLoanDetails.getColumn("EndTime").setHeaderValue("End Time");
        tblLoanDetails.getColumn("Expr2").setHeaderValue("Branch Name");
    }

    private void loadData(String AccNo) {
        try {
            LD = new LoanDetailImp();
            model = new DefaultTableModel();
            rs = LD.getAllLoanDetail();
            model = new DefaultTableModel();
            ResultSetMetaData RSmetaData = rs.getMetaData();
            int colNum = RSmetaData.getColumnCount();
            for (int i = 1; i < colNum + 1; i++) {
                String comName = RSmetaData.getColumnName(i);
                model.addColumn(comName);
            }
            Object[] row = new Object[colNum];
            while (rs.next()) {
                for (int j = 1; j < colNum + 1; j++) {
                    row[j - 1] = rs.getObject(j);
                }
                model.addRow(row);
            }

            LD = new LoanDetailImp();
            LoanTypeImp LT = new LoanTypeImp();
            rsLoanType = LT.getAllLoanType();
            while (rsLoanType.next()) {
                cboLoanType.addItem(rsLoanType.getString("TypeName"));
            }
            acc = new AccountManagerImpl();
            VecAcc = acc.getAll();
            int numAcc = VecAcc.size();
            for (int i = 0; i < numAcc; i++) {
                Vector v = (Vector) VecAcc.get(i);
                cboAccount.addItem(v.get(0));
            }
            String AccFromDB;
            for (int i = 0; i < numAcc; i++) {
                Vector v = (Vector) VecAcc.get(i);
                AccFromDB = v.get(0).toString();
                boolean reg = AccFromDB.equalsIgnoreCase(AccNo);
                if (reg) {
                    cboAccount.setSelectedItem(v.get(0));
                }
            }

            bra = new BranchesManagerImpl();
            VecBra = bra.GetListFromTable("Select * From [Branches]");
            int numBra = VecBra.size();
            for (int i = 0; i < numBra; i++) {
                Vector v = (Vector) VecBra.get(i);
                cboBranch.addItem(v.get(1));
            }

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
        tblLoanDetails.setModel(model);
        tblLoanDetails.removeColumn(tblLoanDetails.getColumn("AccountNo"));
        tblLoanDetails.removeColumn(tblLoanDetails.getColumn("Expr1"));
        tblLoanDetails.removeColumn(tblLoanDetails.getColumn("LoanID"));
        tblLoanDetails.getColumn("Name").setHeaderValue("Customer Name");
        tblLoanDetails.getColumn("TypeName").setHeaderValue("Loan type");
        tblLoanDetails.getColumn("LoanMoney").setHeaderValue("Original Loan");
        tblLoanDetails.getColumn("CurentMoney").setHeaderValue("Remaining Amount");
        tblLoanDetails.getColumn("BeginTime").setHeaderValue("Start Time");
        tblLoanDetails.getColumn("EndTime").setHeaderValue("End Time");
        tblLoanDetails.getColumn("Expr2").setHeaderValue("Branch Name");
    }
}
